<template>
	<uni-nav-bar title="加注机存量调整单列表" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<view class="package datas">
		<uni-datetime-picker v-model="range" type="daterange" :border="false" :clear-icon="false" rangeSeparator="至"
			@change="change" />
	</view>
	<scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
		:style="{ height: pageHeight + 'px' }">
		<DocumentList :orderLists="orderLists" type='加注机'></DocumentList>
		<Popu v-if="orderLists.length<1" :pageHeight="pageHeight" text="暂无加注机存量调整单"></Popu>
	</scroll-view>
	<!-- @click="navTo('administrator/document/filling/addAccount')" -->
	<view class="add" @click="navTo('Sale/inventory/addInventory?type=addAccount&change=1')">新增调整单</view>
</template>

<script setup lang="ts">
	import Popu from '@c/earthPushing/common/popu.vue';
	import { navBack, navTo } from '@/utils/navigator';
	import DocumentList from '@c/administrator/List/documentList.vue';
	import { onShow } from '@dcloudio/uni-app';
	import { ref } from 'vue';
	import { showLoading } from '@/utils/prompt';
	import { format, subDays } from 'date-fns';
	import { toPublish } from '@mqtt';
	import { getBillFillAccount } from '@/gql/administrator';
	/**
	 * 加注机存量调整单列表
	 * @param {Number} pageHeight  滑动视图
	 * @param {Number} lastPage  总页数
	 * @param {Number} currentPage  当前页数
	 * @param {Array} orderLists  加注机列表
	 */
	let now = new Date();
	let end = format(now, 'yyyy-MM-dd');
	let daysAgo = subDays(now, 6);
	let start = format(daysAgo, 'yyyy-MM-dd');
	const range = ref([start, end]);
	const pageHeight = ref();
	const lastPage = ref(1);
	const currentPage = ref(1);
	const orderLists = ref([]);
	uni.getSystemInfo({
		success: function (res) {
			pageHeight.value = res.windowHeight - 190;
		},
	});
	onShow(() => {
		currentPage.value = 1
		orderLists.value = []
		init()
	})
	/**
	 * 初始化获取加注订单列表
	 * @param page  获取当前页加注数据
	 * @param start  开始时间
	 * @param end  结束时间
	 */
	init()
	function init() {
		showLoading()
		const payload = {
			query: getBillFillAccount,
			variables: {
				page: currentPage.value,
				start,
				end
			},
		};
		toPublish(
			'ql/control/getBillFillAccount',
			payload,
			(obj : any) => {
				uni.hideLoading();
				const { getBillFillAccount } = obj.data;
				orderLists.value = [...orderLists.value, ...getBillFillAccount.list];
				lastPage.value = getBillFillAccount.lastpage;
			}
		);
	}
	/**
	 * 加载更多
	 */
	function loadMore() {
		if (currentPage.value < lastPage.value) {
			currentPage.value++;
			init();
		}
	}
	/**
	 * 时间筛选
	 * @param sta  开始时间
	 * @param en  结束时间
	 */
	function change([sta, en] : any) {
		start = sta;
		end = en;
		currentPage.value = 1
		orderLists.value = []
		init()
	}
</script>

<style scoped lang="less">
	.add {
		width: 480rpx;
		height: 100rpx;
		background: linear-gradient(-10deg, #2C96F9, #1B91FF);
		border-radius: 5px;
		text-align: center;
		line-height: 100rpx;
		color: #fff;
		margin: 20rpx auto;
		font-size: 32rpx;
	}

	.taem:nth-of-type(1) {
		margin-top: 0px;
	}

	.top {
		margin-top: 10rpx;
	}
</style>
<style>
	.datas>>>.uni-date__x-input {
		font-size: 30rpx !important;
	}

	.datas>>>.uni-date-x {
		font-size: 30rpx !important;
	}

	.datas>>>.uni-icons {
		font-size: 48rpx !important;
	}
</style>